<?php

class App_Methods_Request_SetActive {

  /**
   *
   * @var App_Methods_Data_App
   */
  public $app;
  public $userId;
  public $active;

  public function __construct($params) {
    $this->app = new App_Methods_Data_App($params->app);
    $this->userId = $params->userId;
    $this->active = (int)$params->active;
  }

  public function process() {
    if (!Core_Auth::getInstance()->getUser()->isAdmin())
    	throw new App_Exception_App(4000);
    
    $count = UsersQuery::create()->filterById($this->userId)->update(array('Active' => $this->active));
    if ($count == 0)
    	throw new App_Exception_App(4001);
    
    return new App_Methods_Response_SetActive(true, $this->active);
  }

}